package com.ruibang.glass.portal.controller;

import com.ruibang.glass.portal.entity.NewMenu;
import com.ruibang.glass.portal.service.NewMenuService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * @Author: songJinKang
 * @CreateTime: 2023-10-18  16:18
 * @Description: TODO
 * @Version: 1.0
 */

@RestController
@RequestMapping("/api/new/menu")
@Slf4j
@Api(tags = "新菜单管理")
public class NewMenuController {

    @Autowired
    private NewMenuService newMenuService;


    @ApiOperation(value = "保存菜单", response = ResultBody.class)
    @PostMapping(value = "/saveMenu")
    public ResultBody saveMenu(@RequestBody @Valid NewMenu menu) {
        return newMenuService.saveMenu(menu);
    }

    @ApiOperation(value = "修改菜单", response = ResultBody.class)
    @PutMapping(value = "/edit")
    public ResultBody edit(@RequestBody @Valid NewMenu menu) {
        return newMenuService.edit(menu);
    }

    @ApiOperation(value = "删除菜单", response = ResultBody.class)
    @DeleteMapping(value = "/delete/{menuId}")
    public ResultBody delete(@PathVariable String menuId) {
        return newMenuService.deleteByMenuId(menuId);
    }

    @ApiOperation(value = "获取所有菜单树", response = ResultBody.class)
    @PostMapping(value = "/queryMenuTree")
    public ResultBody queryMenuTree() {
        return newMenuService.queryMenuTree();
    }

    @ApiOperation(value = "根据用户ID获取菜单树", response = ResultBody.class)
    @PostMapping(value = "/getMenuByUserId")
    public ResultBody getMenuByUserId(String userId) {
        log.info("开始根据用户id获取菜单树：{}", userId);
        return newMenuService.getTreeByUserId(userId);
    }

    @ApiOperation(value = "根据角色ID获取菜单ID", response = ResultBody.class)
    @PostMapping(value = "/getMenuByRoleId")
    public ResultBody getMenuByRoleId(String roleId) {
        log.info("开始根据角色id获取菜单树：{}", roleId);
        return newMenuService.getMenuByRoleId(roleId);
    }

    @ApiOperation(value = "获取按钮信息", response = ResultBody.class)
    @GetMapping(value = "/getByUserId/{userId}")
    public ResultBody getByUserId(@PathVariable String userId){
        return newMenuService.getByUserId(userId);
    }
}
